package volatiles;

import java.util.ArrayList;
import java.util.Random;

/**
 * @author: android 超级兵
 * @create: 2022-01-18 17:06
 * TODO
 **/
public class VolatileBean {

    public volatile boolean isRun;

    public class VolatileThread extends Thread {
        @Override
        public void run() {
            super.run();

            System.out.println("执行开始了!!");
            while (!isRun) ;
            System.out.println("执行结束了。。。");
        }
    }

    private void build() throws InterruptedException {

        new VolatileThread().start();

        Thread.sleep(1000);

        isRun = true;

        System.out.println("等待1s了。。");
    }

    public static void main(String[] args) throws InterruptedException {
//        VolatileBean volatileBean = new VolatileBean();
//        volatileBean.build();

        Test test = new Test();
        test.test();

    }

    public static class Test {

        int[] mTestInts = new int[2];
        ArrayList<Integer> mIntList = new ArrayList<>(2);
        int mInt = 23;
        Random mRandom = new Random();

        public void test() {
            loadInts(mTestInts);
            loadIntArray(mIntList);
            loadInt(mInt);

            System.out.println("int[] first:"+mTestInts[0]+"\tsecond:"+mTestInts[1]);
            System.out.println("list first:"+mIntList.get(0)+"\tsecond:"+mIntList.get(1));
            System.out.println("mInt:"+mInt);
        }
        public void loadInt(int tempInt){  tempInt += 52;  }

        public void loadIntArray(ArrayList<Integer> list) {
            list.add(mRandom.nextInt(10));
            list.add(mRandom.nextInt(10));
        }

        public void loadInts(int[] ints) {
            if(ints instanceof Object){System.out.println("int[] extents Object");}
            ints[0] = mRandom.nextInt(10);
            ints[1] = mRandom.nextInt(10);
        }
    }


}
